package com.itic.system.collage.condition.service;

import com.itic.appbase.framework.common.constants.DBConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.system.collage.condition.persistence.dao.CollageConditionDao;
import com.itic.system.collage.condition.persistence.model.CollageCondition;
import com.itic.system.collage.condition.persistence.model.CollageConditionExample;
import com.itic.system.collage.condition.persistence.model.CollageConditionExample.Criteria;

import java.util.List;


@Service
@Transactional
public class CollageConditionService
     extends CrudService<CollageConditionDao,CollageCondition,CollageConditionExample> {
    @Autowired
    private CollageConditionDao collageConditionDao;

    /**
     * 添加拼团价格 人数 条件
     * @param collageId
     * @param collagePeopleCount
     * @param collagePrice
     * @return
     */
    public String  addCollageCondition(String collageId,int collagePeopleCount,double collagePrice){
        CollageCondition collageCondition = new CollageCondition();
        collageCondition.setCollageId(collageId);
        collageCondition.setCollagePeopleNumber(collagePeopleCount);
        collageCondition.setCollagePrice(collagePrice);
        String result = this.add(collageCondition);
        return result;
    }

    /**
     * 根据拼团ID查询拼团价格以及拼团人数  （安拼团人数正序）
     * @param collageId
     * @return
     */
    public List<CollageCondition>  findCollageConditionByCollageId(String collageId){
        CollageConditionExample example = new CollageConditionExample();
        Criteria criteria = example.createCriteria();
        criteria.andIsEffectiveEqualTo(DBConst.TRUE);
        criteria.andCollageIdEqualTo(collageId);
        example.setOrderByClause( " COLLAGE_PEOPLE_NUMBER asc");
        List<CollageCondition> collageConditions = this.list(example);
        return collageConditions;
    }

}